package com.report.controller;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import com.report.dto.response.LogRes;
import com.report.dto.response.MemberRes;
import com.report.service.ActiveUserService;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/9/2 14:43
 */
@RestController
@RequestMapping(value = "/activeUsers")
@Slf4j
@AllArgsConstructor
public class ActiveUsersController {

    private final ActiveUserService activeUserService;

    /**
     * 活跃用户
     * @return
     */
    @GetMapping(value = "/index")
    public Result<List<LogRes>> activeUsers(){
        List<LogRes> lists = activeUserService.lists();
        return Result.successResult(lists);
    }

    @GetMapping(value = "/activeUsersCount")
    public Result<Integer> activeUsersCount(){
        List<String> logIds = StpUtil.searchSessionId("", 0, -1, false);
        return Result.successResult(logIds.size());
    }
}
